package nc.nc_xiuxian;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import static nc.nc_xiuxian.NC_XIUXIAN.plugin;

public class JQHFTACK {
    public static void JQHF(){
        for(Player p:Bukkit.getOnlinePlayers()){
            BukkitRunnable runnable = new BukkitRunnable() {
                int time = 3;
                HashMap<Player,Location>playerlocation=new HashMap<>();
                @Override
                public void run() {
                    Location oldlocation = playerlocation.get(p);
                    if(oldlocation==null){
                        oldlocation=p.getLocation();
                    }
                    Location location = p.getLocation();
                    if(oldlocation.equals(location)){
                        time--;
                        if(time<=0){
                            if(SHUXING.sxloadapi(p,"jq")<SHUXING.sxloadapi(p,"maxjq")){
                                try {
                                    SHUXING.sxsetadd(p,"jq",0.1);
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                            if(SHUXING.sxloadapi(p,"mp")<SHUXING.sxloadapi(p,"maxmp")){
                                try {
                                    SHUXING.sxsetadd(p,"mp",0.1);
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    }
                }
            };
            BukkitTask task=runnable.runTaskTimer(plugin,0L,20L);
            plugin.hfsask.putIfAbsent(p.getName(), task);
            for(String s:plugin.hfsask.keySet()){
                if(Bukkit.getPlayer(s)==null){
                    BukkitTask task1 = plugin.hfsask.get(s);
                    task1.cancel();
                    plugin.hfsask.remove(s);
                }
            }
        }
    }
}
